/**
 *  @file: LcdTask.h
 *  @author: nwz
 *  @brief: 
 *  @date: 2024��8��1��
 * 
 */

#pragma once
#include <all_header.h>

namespace task {

/*
 *
 */
class LcdTask {
public:
	LcdTask(bsp::LCD &lcd,bsp::Backlight &backlight):lcd{lcd},bg{backlight}{

	}
	virtual ~LcdTask();

	int init(uint8_t brightness);
	static void run(LcdTask* task){
		task->run_();
	}

	void run_();

	void updateTime();

	bool isShutdown(){
		return state == State::SHUTDOWN;
	}

	void shutdown();
private:
	uint8_t brightness;
	bsp::Backlight &bg;
	bsp::LCD &lcd;
	uint32_t latest_time = 0;
	bool lcd_off = false;

	uint32_t calculateSleepTicks();
	SemaphoreHandle_t sem;
	enum class State{NORMAL,DARK,SHUTDOWN};
	State state = State::NORMAL;
	void notify();
	void setState(State state);
};

} /* namespace task */
